Page({
  data: {
    userInfo: null
  },

  onLoad: function() {
    // 页面加载时获取用户信息
    this.getUserInfo();
  },

  getUserInfo: function() {
    const app = getApp();
    this.setData({
      userInfo: app.globalData.userInfo
    });
  },

  onSwitchRole: function() {
    wx.navigateTo({
      url: '/pages/auth/roleSwitch'
    });
  },

  onLogout: function() {
    // 清除本地存储的token
    wx.removeStorageSync('token');
    
    // 重置全局数据
    const app = getApp();
    app.globalData.token = null;
    app.globalData.userInfo = null;
    
    // 跳转到登录页面
    wx.redirectTo({
      url: '/pages/auth/login'
    });
  }
});